package com.itheima.a01_ApplicationContext比BeanFactory多点啥;

import org.springframework.context.MessageSource;
import org.springframework.context.support.GenericApplicationContext;
import org.springframework.context.support.ResourceBundleMessageSource;

import java.util.Locale;

/**
 * 国际化
 */
public class TestMessageSource {
    public static void main(String[] args) {
        //GenericApplicationContext 是一个【干净】的容器,是指没有添加BeanFactory后处理器,Bean后处理器(就是不解析 @Autowired这些注解)
        GenericApplicationContext context = new GenericApplicationContext();

        context.registerBean("messageSource", MessageSource.class, () -> {
            ResourceBundleMessageSource ms = new ResourceBundleMessageSource();
            ms.setDefaultEncoding("utf-8");
            ms.setBasename("messages");
            return ms;
        });

        //刷新Spring容器，刷新的意思即把BeanFactory清空为初始状态，然后再按照程序意图填满各种Bean
        context.refresh();

        System.out.println(context.getMessage("hi", null, Locale.ENGLISH));
        System.out.println(context.getMessage("hi", null, Locale.CHINESE));
        System.out.println(context.getMessage("hi", null, Locale.JAPANESE));
    }
}
